import java.util.*;
import java.sql.*;

public class DataBaseUpdate {

    private String dbDriverName    = "sun.jdbc.odbc.JdbcOdbcDriver";
    private String dataBaseName    = "jdbc:odbc:stock_record";
    private String userName        = "wli";
    private String password        = "4test";
    private String queryString     = null;
    private static String tick = "";
    private StringBuffer output = new StringBuffer();
    private static int i =1;

    public static void main (String args[]) {

	DataBaseUpdate dbUpdate = new DataBaseUpdate();

	String query = "UPDATE test_record SET DATE='09/09/2002'";

	dbUpdate.setQueryString(query);
	dbUpdate.updateData();
    }

    public void setQueryString (String query_string) {
	queryString = query_string;
    }

    public int updateData() {

	String driverName  = dbDriverName;
	String dbURL       = dataBaseName;
	String theUser     = userName;
	String thePwd      = password;
	int result = 0;

      try {
	  Class.forName(driverName);
	  Connection con = DriverManager.getConnection(dbURL, theUser, thePwd);
	  Statement statement = con.createStatement();

	  output.append( "\nSending query: " +  con.nativeSQL( queryString ) + "\n");

	  result = statement.executeUpdate( queryString );

	  if ( result == 1 )
	      output.append( "\nInsertion successful\n" );
	  else {
	      output.append( "\nInsertion failed\n" );
	  }

	  statement.close();
	  con.close();
	  System.out.println(output);
	
      }
      catch ( SQLException sqlex ) {
         sqlex.printStackTrace();
         output.append( sqlex.toString() );
	 System.out.println(output);

      } catch (java.lang.Exception ex) {
	  ex.printStackTrace();
      }
      return result;
    }
}

